home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE18
/
FONTS
/
PRD16.DPR
< prev
next >
Wrap
Text File
|
1996-11-02
|
3KB
|
94 lines
program Prd16;
uses
{Next uses line needed for dynamic font stuff}
{$ifdef WIN32}
windows, messages, sysutils,
{$else}
wintypes, winprocs, messages, sysutils,
{$endif}
Forms,
Fd16 in 'FD16.PAS' {Form1};
{$R *.RES}
{ Returns the path to the system's TEMP dir (Win16 and Win32)}
function strTempPath : string;
var
strTempPath : string;
{$ifdef WIN32}
nChars : integer;
{$endif}
begin
{$ifdef WIN32}
SetLength(strTempPath,255); // allocate 255 chars in the string
nChars := GetTempPath(254,PChar(strTempPath)); // get the temp location
// Check that GetTempPath worked ok
if (nChars = 0) or (nChars > 254) then
raise Exception.Create('Can not get location of TEMP directory');
{$else}
strTempPath := GetTempDrive('x');
{$endif}
result := strTempPath;
end;
procedure LoadFont(name : string);
var
pstrFotFile, pstrTmp, pzttf : array [0..250] of char;
ttf : string;
begin
{Create a path to this directory & the font file}
ttf := ExtractFilePath(Application.ExeName) + name + '.ttf';
{We want to create the .fot files in the temp dir}
{$ifdef WIN32}
GetTempFileName(PChar(strTempPath), PChar(name), 1, pstrFotFile);
{$else}
GetTempFileName(GetTempDrive('x'), StrPCopy(pstrTmp,name), 1, pstrFotFile);
{$endif}
StrPCopy(pzttf,ttf);
{if the fot file exists then delete it}
DeleteFile(StrPas(pstrFotFile));
{Load the font}
if not CreateScalableFontResource(0,pstrFotFile,pzttf,nil) then
raise Exception.Create('Error in CreateScaleableFontResource.'+#10+ttf);
if AddFontResource(pstrFotFile) = 0 then
raise Exception.Create('Error in AddFontResources ' + name);
end;
procedure RemoveFont(name : string);
var
pstrFotFile, pstrTmp : array [0..150] of char;
begin
{We'll find the .fot files in the temp dir}
{$ifdef WIN32}
GetTempFileName(PChar(strTempPath), PChar(name), 1, pstrFotFile);
{$else}
GetTempFileName(GetTempDrive('x'), StrPCopy(pstrTmp,name), 1, pstrFotFile);
{$endif}
if not RemoveFontResource(pstrFotFile) then
raise Exception.Create('Error in RemoveFontResource '+name);
DeleteFile(StrPas(pstrFotFile));
end;
procedure LoadFonts;
begin
LoadFont('acce'); {Accent SF}
{ LoadFont('xxx'); Repeat for as many fonts as required }
{Inform the system that the fonts have changed}
SendMessage($FFFF,WM_FONTCHANGE,0,0);
end;
procedure DeleteFonts;
begin
RemoveFont('acce');
{ RemoveFont('xxx'); This list must match the one in LoadFonts }
{Inform the system that the fonts have changed}
SendMessage($FFFF,WM_FONTCHANGE,0,0);
end;
begin
LoadFonts;
Application.CreateForm(TForm1, Form1);
Application.Run;
DeleteFonts;
end.